﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class player : MonoBehaviour {
    private Rigidbody rd;
    private int score;
    public Text text;
    public GameObject wintext1;
	// Use this for initialization
	void Start () {
        rd = GetComponent<Rigidbody>();
	
	}
	
	// Update is called once per frame
	void Update () {
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical"); 
        rd.AddForce(new Vector3(h, 0, v)*5);
         
	}
    //碰撞检测 
    void OnCollisionEnter(Collision collision)
    { //collision.collider//获取碰撞到的游戏物体身上的collider组件
      //string name = collision.collider.name;
      // print(name);
        if (collision.collider.tag == "pick up") {
            Destroy(collision.collider.gameObject);
        }


    }
    void OnTriggerEnter(Collider collider) {
        if (collider.tag == "pick up") {
             Destroy(collider.gameObject);
            score++;
            text.text = score.ToString();
            if (score == 5)
            { wintext1.SetActive(true); }
        }
    }
}
